package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IStatusOfTransferingRequestDAO;
import com.AAL.Model.StatusOfTransferingRequest;
import com.AAL.Utils.HibernateUtil;

public class StatusOfTransferingRequestDAO implements
		IStatusOfTransferingRequestDAO {

	@Override
	public StatusOfTransferingRequest getStatusOfTransferingRequest(int statusID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StatusOfTransferingRequest statusOfTransferingRequest = (StatusOfTransferingRequest) session
				.load(StatusOfTransferingRequest.class,(short) statusID);
		return statusOfTransferingRequest;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StatusOfTransferingRequest> getAllStatusOfTransferingRequests() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StatusOfTransferingRequest> lstStatusOfTransferingRequests = null;
		try {

			lstStatusOfTransferingRequests = (List<StatusOfTransferingRequest>) session
					.createQuery("from StatusOfTransferingRequest").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstStatusOfTransferingRequests;
	}

}
